<template>
    <div class="goods-list">
        <!-- <router-link :to="'/home/goosInfo/'+item.id" class="goods-item" v-for="item in goodsList" :key="item.id" tag="div">
            <img :src="item.img">
            <h1 class="title">{{ item.name }}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{ item.newP}}</span>
                    <span class="old">￥{{ item.oldP }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.count }}件</span>
                </p>
            </div>
        </router-link> -->

    <!-- 在网页中有两种跳转方式  -->
    <!-- 1. a 标签 -->
    <!-- 2. window.location.href 的形式，叫做 编程式导航-->
        <div  class="goods-item" v-for="item in goodsList" :key="item.id" @click="gdetile(item.id)">
            <img :src="item.img">
            <h1 class="title">{{ item.name }}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{ item.newP}}</span>
                    <span class="old">￥{{ item.oldP }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.count }}件</span>
                </p>
            </div>
        </div>

        <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                pageindex: 1,// 分页，默认第一页
                goodsList: [],
            }
        },
        methods: {
            gdetile(id){ // 使用 js 形式进行跳转
                 // this.$route 是一个 [参数对象]，所有路由中的参数， params , query 都属于它
               //  this.$router 是一个路由 [导航对象] ， 用它可以方柏霓的使用 JS 代码，实现路由的 前进，后退，跳转新的 url
               // 1. 是最简单的 
                // this.$router.push('/home/goosInfo/'+id)
                // 2. 传递对象
                // this.$router.push({ path: '/home/goosInfo/'+id})
                // 3.传递一个命名的路由, path 不能和 params 一起使用
                this.$router.push({ name: 'goodsinfo', params: { id }})
                // 4.
                // this.$router.push({ name: 'goodsinfo', query: { id }})
            },
            getMore(){
                 var list = [
                    { id:'7', name: '复活节卡', date: '2019-09-10', count: '43', img: '../../images/19.gif', newP: 2399, oldP: 2599},
                    { id:'8', name: '阿贾克斯发', date: '2019-09-10', count: '321', img: '../../images/5.jpg', newP: 899, oldP: 999},
                    { id:'9', name: '发哈尽快', date: '2019-09-10', count: '32', img: '../../images/6.jpg', newP: 1499, oldP: 2099},
                    { id:'10', name: '纺纱机', date: '2019-09-10', count: '331', img: '../../images/7.jpg', newP: 87, oldP: 120},
                    { id:'11', name: '纺纱机', date: '2019-09-10', count: '233', img: '../../images/8.jpg', newP: 1459, oldP: 267},
                    //{ id:'12', name: '纺纱机', date: '2019-09-10', count: '313', img: '../../images/0.jpg', newP: 2399, oldP: 2599},
             ]
                this.goodsList = this.goodsList.concat(list)
            },
            getGoodsList(){
                var list = [
                    { id:'1', name: '健身卡尽快', date: '2019-09-08', count: '41', img: '../../images/11.jpg', newP: 2399, oldP: 2599},
                    { id:'2', name: '的就撒开附件是的回复', date: '2019-09-09', count: '2', img: '../../images/12.jpg', newP: 399, oldP: 599},
                    { id:'3', name: '是积分卡', date: '2019-09-10', count: '3', img: '../../images/13.jpg', newP: 3499, oldP: 5399},
                    { id:'4', name: '飞机萨科', date: '2019-09-10', count: '32', img: '../../images/14.jpg', newP: 1299, oldP: 4399},
                    { id:'5', name: '书法家开好房间', date: '2019-09-10', count: '13', img: '../../images/15.jpg', newP: 599, oldP: 899},
                    { id:'6', name: '飞机萨科', date: '2019-09-10', count: '33', img: '../../images/17.gif', newP: 3299, oldP: 5499},
             ]
                this.goodsList = list
            },
        },
        created(){
            this.getGoodsList()
        },
    }
</script>

<style lang="scss" scoped>
.goods-list{
    display: flex;
    flex-wrap: wrap;
    padding: 12px;
    justify-content: space-between;
    .goods-item{
        width: 49%;
        margin: 3px 0;
        padding: 2px;
        border: 1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        min-height: 210px;
        img{
            width: 100%;
        }
        .title{
            font-size: 14px;
        }
        .info{
            background-color: #eee;
            p{
                margin: 0;
                padding: 5px;
            }
            .price{
                .now{
                    color: red;
                    font-weight: bold;
                    font-size: 16px;
                }
                .old{
                    text-decoration: line-through;
                    font-size: 12px;
                    margin-left: 10px;
                }
            }
            .sell{
                display: flex;
                justify-content: space-between;
                font-size: 13px;
            }
        }
    }
}
</style>